home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / mis_cnvt / txt2db / nthat.prg < prev    next >
Text File  |  1994-01-05  |  1KB  |  46 lines

  1. /***
  2.  * Program : NTHAT.PRG
  3.  * Notice  : Copyright (c) BITwise Computer Services, 1991-1992
  4.  * Date    : 09/17/92
  5.  * Author  : David Christian
  6.  * Purpose :
  7.  * Notes   : Compile with /n /w
  8.  *
  9.  * Revised :
  10.  *
  11. */
  12.  
  13. #include"txt2dbf.ch"
  14.  
  15. FUNCTION B_NTHAT(cSearch,cTarget,nTh)
  16.    // SYNTAX: <expN1>:=B_NthAT(<expC1>,<expC2>,[<expN2>])
  17.    //         - RETURNS POS OF THE nTh OCCURANCE OF cSearch IN cTarget
  18.    //         - SEARCHES LEFT TO RIGHT
  19.    //         - RETURNS 0 IF nTh OCCURANCE NOT FOUND
  20.    //
  21.    LOCAL nPos:=0, nAt:=0, nX:=0
  22.    DEFAULT nTh TO 1
  23.    WHILE nX<nTh .AND. ( nAt:=AT(cSearch,SUBSTR(cTarget,nPos+1)) ) >0
  24.       nX++
  25.       nPos+=nAt
  26.    END
  27. RETURN( IIF(nAt==0,0,nPos) )
  28.  
  29.  
  30. FUNCTION B_NTHRAT(cSearch,cTarget,nTh)
  31.    // SYNTAX: <expN1>:=B_NthRAT(<expC1>,<expC2>,[<expN2>])
  32.    //         - RETURNS POS OF THE nTh OCCURANCE OF cSearch IN cTarget
  33.    //         - SEARCHES RIGHT TO LEFT
  34.    //         - RETURNS 0 IF nTh OCCURANCE NOT FOUND
  35.    //
  36.    //
  37.    LOCAL nAt:=LEN(cTarget)+1, nX:=0
  38.    DEFAULT nTh TO 1
  39.    WHILE nX<nTh .AND. ( nAt:=RAT(cSearch,SUBSTR(cTarget,1,nAt-1)) ) >0
  40.       nX++
  41.    END
  42. RETURN(nAt)
  43.  
  44.  
  45. //EOF
  46.